home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / utilitys / 47 / strtgem2.s < prev   
Encoding:
Text File  |  1987-03-30  |  6.3 KB  |  252 lines

  1. *******************************************************************************
  2. * STRTGEM2.S - A program to auto-start a GEM application
  3. *
  4. * Converted to AS68 format and modified by Charles F. Johnson
  5. *
  6. * Last revision: 03/16/87  14:41:28
  7. *******************************************************************************
  8.  
  9. * Original comments:
  10. *******************************************************************************
  11. * STARTGEM.S    6-MAR-1987      by GHOST-Soft
  12. *
  13. * This program is used to start GEM programs from within the AUTO folder.
  14. *
  15. * The code is probably highly nonportable, as it heavily depends on the
  16. * internal organisation of code in TOS/GEM.
  17. * As this program works with ROM- as well as all disk-based versions
  18. * of German TOS, I'm pretty sure that this program works with foreign
  19. * versions of TOS, too.
  20. *******************************************************************************
  21.  
  22.  
  23. linef        =    $2C
  24. vbllist1    =    $04D2
  25.  
  26. gemdos        =    1
  27. xbios        =    14
  28.  
  29.  
  30.     .text
  31.  
  32.     lea    basepage(pc),a0    Get basepage address
  33.     move.l    $4(a7),(a0)
  34.  
  35.     clr.w    -(sp)        Try to open STARTGEM.INF
  36.     pea    startgem(pc)
  37.     move.w    #$3D,-(sp)
  38.     trap    #gemdos
  39.     addq.l    #8,sp
  40.     tst.w    d0        Error?
  41.     bpl    continue    No, forge onward
  42.  
  43.     pea    error(pc)    Let the user know that he's short one
  44.     move.w    #9,-(sp)    STARTGEM.INF file
  45.     trap    #gemdos
  46.     addq.l    #6,sp
  47.     move.w    #1,-(sp)    Wait for a key
  48.     trap    #gemdos
  49.     addq.l    #2,sp
  50.     bra    wipeout        And bail out
  51.  
  52. continue:
  53.     lea    handle(pc),a5
  54.     move.w    d0,(a5)        Save GEMDOS file handle
  55.  
  56.     pea    filename(pc)    Set buffer address
  57.     move.l    #64,-(sp)    64 bytes maximum
  58.     move.w    (a5),-(sp)    File handle
  59.     move.w    #$3F,-(sp)
  60.     trap    #gemdos        Read STARTGEM.INF
  61.     add.l    #12,sp
  62.     tst.l    d0        Error?
  63.     bmi    wipeout        GERONIMO!
  64.  
  65.     lea    filename(pc),a0
  66.     add.l    d0,a0        Number of bytes read is in d0
  67.     clr.b    -2(a0)        Set zero at end of filename (before CR/LF)
  68.  
  69.     move.w    (a5),-(sp)    Close the file
  70.     move.w    #$3E,-(sp)
  71.     trap    #gemdos
  72.     addq.l    #4,sp
  73.  
  74.     clr.l    -(a7)
  75.     move.w    #$20,-(a7)    Enter super mode
  76.     trap    #gemdos
  77.     addq.w    #6,a7        Keep old super sp in d0
  78.  
  79.     moveq.l    #$FF,d2
  80.     move.l    d2,linef    set line-f emulator trap
  81.     move.l    #vbllist1,a5    Start searching at second vector
  82.     move.w    #6,d5
  83. ckvb1:    tst.l    (a5)        Let's find an empty VBI slot in the queue
  84.     beq    ckvb2        Got one, skip ahead
  85.     addq.l    #4,a5        Keep searching
  86.     dbf    d5,ckvb1
  87.     pea    novbileft    Print error message
  88.     move.w    #9,-(sp)
  89.     trap    #gemdos
  90.     addq.l    #6,sp
  91.     bra    wipeout        And split
  92. ckvb2:    lea    vblank(pc),a2
  93.     move.l    a2,(a5)        Set VBI vector
  94.     lea    vbiptr(pc),a2
  95.     move.l    a5,(a2)        Save address of the vector we changed
  96.  
  97.     move.l    d0,-(a7)
  98.     move.w    #$20,-(a7)    exit super mode
  99.     trap    #gemdos
  100.     addq.w    #6,a7
  101.  
  102.     lea    basepage(pc),a0    compute number of bytes to keep
  103.     suba.l    basepage(pc),a0
  104.     clr.w    -(a7)        0 = no error
  105.     move.l    a0,-(a7)
  106.     move.w    #$31,-(a7)    terminate and stay resident
  107.     trap    #gemdos        this call never returns
  108.  
  109. wipeout:
  110.     clr.w    -(sp)        If something goes wrong we end up here 
  111.     trap    #gemdos        (hopefully)
  112.  
  113. vblank:    moveq.l    #$FF,d0
  114.     cmp.l    linef,d0
  115.     beq    H96
  116.     lea    vbiptr(pc),a0
  117.     move.l    (a0),a0
  118.     clr.l    (a0)        Clear vblank vector
  119.     movea.l    linef,a0
  120.     lea    old_lf(pc),a1
  121.     move.l    a0,(a1)        save old line-f vector (usually in low RAM)
  122.     lea    new_lf(pc),a1
  123.     move.l    a1,linef    install new one
  124.  
  125. * Find the address of the buffer that GEM uses for the
  126. * name of the program it is going to execute
  127.  
  128.     movea.l    $16(a0),a0    get start of line-f table from instruction
  129.     movea.l    $7C8(a0),a0    get address of routine 'f7c8' from table
  130.     movea.l    $A(a0),a2    get address from instruction
  131.     adda.w    $10(a0),a2    add offset 0x1f56 from instruction
  132.     lea    pointer(pc),a1
  133.     move.l    a2,(a1)        save buffer address
  134. H96:
  135.     rts
  136.  
  137. new_lf:    movea.l    $2(a7),a0    get addr. of instr. that caused exception
  138.     cmpi.w    #$F08C,(a0)    'f08c' is the line-f instr. we're looking for
  139.     bne    exit
  140.     move.l    old_lf(pc),linef restore old line-f vector
  141.  
  142.     movea.l    pointer(pc),a0
  143.     lea    filename(pc),a1
  144. HB4:    move.b    (a1)+,(a0)+    copy filename into GEM buffer space
  145.     bne    HB4
  146.  
  147.     pea    dta
  148.     move.w    #$1A,-(a7)    set DTA
  149.     trap    #gemdos
  150.     addq.l    #6,a7
  151.     move.w    #$27,-(a7)    don't look at volumes and directories
  152.     pea    filename(pc)
  153.     move.w    #$4E,-(a7)    search first
  154.     trap    #gemdos
  155.     addq.l    #8,a7
  156.     tst.w    d0        status <> 0 indicates error
  157.     bne    exit
  158.  
  159.     lea    filename(pc),a5 Pointer to filename
  160.     clr.w    d0
  161.     move.b    (a5)+,d0    Get drive specifier
  162.     and.w    #$DF,d0        Mask off lowercase
  163.     sub.b    #65,d0        Convert from ASCII
  164.     move.w    d0,-(sp)
  165.     move.w    #$0E,-(sp)
  166.     trap    #gemdos        Set current drive
  167.     addq.l    #4,sp
  168.  
  169.     addq.l    #1,a5
  170.     lea    pathname(pc),a4
  171.     move.w    #63,d5
  172. pathlp:    tst.b    (a5)        Build a pathname from the filename
  173.     beq    plx1        supplied by the user
  174.     move.b    (a5)+,(a4)+
  175.     dbf    d5,pathlp
  176. plx1:    move.w    #63,d5
  177. plp2:    cmp.b    #'\',-(a4)
  178.     beq    plx2
  179.     dbf    d5,plp2
  180. plx2:    addq.l    #1,a4
  181.     clr.b    (a4)
  182.     pea    pathname    Set path
  183.     move.w    #$3B,-(sp)
  184.     trap    #gemdos
  185.     addq.l    #6,sp
  186.  
  187.     movea.l    $2(a7),a0    get addr. of instr. that caused exception
  188. HDE:    cmpi.w    #$F4B8,(a0)    look for line-f instruction 'f4b8'
  189.     beq    doload
  190.     addq.l    #2,a0
  191.     cmpa.l    #$FEFFFE,a0    test for ROM end
  192.     beq    exit
  193.     cmpa.l    #$78000,a0    test for RAM end (on 512K machine)
  194.     bne    HDE        {RAM-TOS usually loads much lower}
  195.  
  196. exit:    movea.l    old_lf(pc),a0    resume execution of regular line-f handler
  197.     jmp    (a0)
  198.  
  199. doload:
  200.     move.w    (a7)+,d2    pop status word
  201.     addq.w    #4,a7        destroy addr. of instr. 'f08c'
  202.     move    d2,sr        restore status register
  203.     adda.w    #$38,a7        destroy parameters of instr. 'f08c'
  204.     jmp    (a0)        jump to instruction 'f4b8'
  205.  
  206.     .even
  207.  
  208. dta:    ds.b    44
  209.  
  210. old_lf:    ds.l    1
  211.  
  212. pointer:
  213.     ds.l    1
  214.  
  215. vbiptr:
  216.     ds.l    1
  217.  
  218. handle:
  219.     ds.w    1
  220.  
  221. filename:
  222.     ds.b    72
  223.  
  224. pathname:
  225.     ds.b    64
  226.  
  227. startgem:
  228.     dc.b    'STARTGEM.INF',0
  229.  
  230. error:
  231.     dc.b    "Error! - Can't find STARTGEM.INF...",13,10,13,10
  232.     dc.b    '  To use STARTGEM.PRG, first create',13,10
  233.     dc.b    'a text file called STARTGEM.INF in',13,10
  234.     dc.b    'the main directory of your boot disk,',13,10
  235.     dc.b    'consisting of the filename of the',13,10
  236.     dc.b    'program you wish to auto-run.',13,10,13,10
  237.     dc.b    '  The first three characters of this',13,10
  238.     dc.b    'filename MUST consist of the drive',13,10
  239.     dc.b    'name (A, B, etc.), a colon, and a',13,10
  240.     dc.b    'backslash.  Examples:',13,10,13,10
  241.     dc.b    'A:\1STWORD.PRG',13,10
  242.     dc.b    'C:\UTILITY\ARC\ARC.TTP',13,10,13,10
  243.     dc.b    'Press any key to exit.',13,10,0
  244.  
  245. novbileft:
  246.     dc.b    'Oops! No vertical blank interrupt',13,10
  247.     dc.b    'vectors left!',13,10,0
  248.  
  249.     .even
  250. basepage:
  251.     dc.b    'EOPA'
  252.